@extends('layout.main')

@section('content')
<div class="row">
    <div class="col-lg-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>权限设置</h5>
            </div>
            <div class="ibox-content">
                <form class="form-horizontal" id="form" role="form" method="post" action='/role/set'>
                    <input type="hidden" name="role_id" value="{{$role_id}}">
                    <table class="table">
                        {!! csrf_field() !!}
                        {!!$html_tree!!}
                    </table>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <button class="btn btn-white" type="reset">取消</button>
                            <button class="btn btn-primary" type="submit">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection

@section('js')
<!-- page specific plugin scripts -->

<!-- inline scripts related to this page -->
<script type="text/javascript">
    
    function checknode(obj)
    {
        var chk = $("input[type='checkbox']");
        var count = chk.length;

        var num = chk.index(obj);

        var level_top = level_bottom =  chk.eq(num).attr('level');
        for (var i=num; i>=0; i--)
        {
            var le = chk.eq(i).attr('level');
            if(parseInt(le) < parseInt(level_top)) 
            {
                chk.eq(i).prop("checked",'checked');
                var level_top = level_top-1
            }
        }
        for (var j=num+1; j<count; j++)
        {
            var le = chk.eq(j).attr('level');
            if(chk.eq(num).is(':checked')) {
                if(parseInt(le) > parseInt(level_bottom)) chk.eq(j).prop("checked",'checked');
                else if(parseInt(le) == parseInt(level_bottom)) break;
            }
            else {
                if(parseInt(le) > parseInt(level_bottom)) chk.eq(j).prop("checked",false);
                else if(parseInt(le) == parseInt(level_bottom)) break;
            }
        }
    }

       
</script>
@endsection